home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / LSSETVBU.C < prev    next >
Text File  |  1991-09-23  |  2KB  |  95 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)lssetvbu.c    1.5 - 91/09/23" */
  5.  
  6. #include <ansi.h>
  7.  
  8. /* ansi headers */
  9. #include <errno.h>
  10. #ifdef AC_STDDEF
  11. #include <stddef.h>
  12. #endif
  13.  
  14. /* local headers */
  15. #include <blkio.h>
  16.  
  17. /* local headers */
  18. #include "lseq_.h"
  19.  
  20. /*man---------------------------------------------------------------------------
  21. NAME
  22.      lssetvbuf - assign buffering to an lseq
  23.  
  24. SYNOPSIS
  25.      #include <lseq.h>
  26.  
  27.      int lssetvbuf(lsp, buf, bufcnt)
  28.      lseq_t *lsp;
  29.      void *buf;
  30.      size_t bufcnt;
  31.  
  32. DESCRIPTION
  33.      The lssetvbuf function is used to assign buffering to an lseq.
  34.      bufcnt specifies the number of lseq records to be buffered.  If
  35.      bufcnt has a value of zero, the lseq will be completely
  36.      unbuffered.  If buf is not the NULL pointer, the storage area it
  37.      points to will be used instead of one automatically allocated for
  38.      buffering.
  39.  
  40.      The size of the storage area needed can be obtained using the
  41.      LSBUFSIZE() macro:
  42.  
  43.           char buf[LSBUFSIZE(RECSIZE, BUFCNT)];
  44.           lssetvbuf(lsp, buf, BUFCNT);
  45.  
  46.      where RECSIZE is the size of the keys int the lseq, and BUFCNT is
  47.      the number of records to buffer.
  48.  
  49.      Any previously buffered data is flushed before installing the new
  50.      buffer area, so lssetvbuf may be called more than once.  This
  51.      allows the buffer size to be varied with the file size.
  52.  
  53.      lssetvbuf will fail if one or more of the following is true:
  54.  
  55.      [EINVAL]       lsp is not a valid lseq pointer.
  56.      [LSENOPEN]     lsp is not open.
  57.  
  58. SEE ALSO
  59.      lssetbuf, lssync.
  60.  
  61. DIAGNOSTICS
  62.      Upon successful completion, a value of 0 is returned.  Otherwise,
  63.      a value of -1 is returned, and errno set to indicate the error.
  64.  
  65. ------------------------------------------------------------------------------*/
  66. #ifdef AC_PROTO
  67. int lssetvbuf(lseq_t *lsp, void *buf, size_t bufcnt)
  68. #else
  69. int lssetvbuf(lsp, buf, bufcnt)
  70. lseq_t *lsp;
  71. void *buf;
  72. size_t bufcnt;
  73. #endif
  74. {
  75.     /* validate arguments */
  76.     if (!ls_valid(lsp)) {
  77.         errno = EINVAL;
  78.         return -1;
  79.     }
  80.  
  81.     /* check if not open */
  82.     if (!(lsp->flags & LSOPEN)) {
  83.         errno = LSENOPEN;
  84.         return -1;
  85.     }
  86.  
  87.     /* set buffering */
  88.     if (bsetvbuf(lsp->bp, buf, ls_blksize(lsp), bufcnt) == -1) {
  89.         LSEPRINT;
  90.         return -1;
  91.     }
  92.  
  93.     return 0;
  94. }
  95.